<?php
// +----------------------------------------------------------------------
// | 名片应用
// | Author: 张亚 < zhyacn@gmail.com>
// +----------------------------------------------------------------------
namespace app\businesscard\controller;

use app\businesscard\model\BusinessCategoryModel;
use app\businesscard\service\CardService;
use cmf\controller\HomeBaseController;

class IndexController extends HomeBaseController {
	public function index() {

		$param = $this->request->param();

		$categoryId = $this->request->param('category', 0, 'intval');

		$cardService = new CardService();
		$data = $cardService->adminCardList($param);

		$data->appends($param);

		$businessCategoryModel = new BusinessCategoryModel();
		$categoryTree = $businessCategoryModel->adminCategoryTree($categoryId);

		$this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
		$this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
		$this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
		$this->assign('cards', $data->items());
		$this->assign('category_tree', $categoryTree);
		$this->assign('category', $categoryId);
		$this->assign('page', $data->render());

		return $this->fetch(':index');
	}
}
